﻿//澶撮儴鐧诲綍楠岃瘉
function chkloginForm(From) {
    var username = document.getElementById('username_head');
    if (username.value == '请输入邮箱或者手机号' || username.value == '')
    { alert('请输入邮箱或者手机号'); username.focus(); return false; }

    //瀵嗙爜
    var password = document.getElementById('password_head').value;
    if (password == "请输入登陆密码" || password == "")
    { alert('请输入登陆密码'); return false; }

    if (password.length < 6 || password.length > 20)
    { alert('密码应在6-20位之间'); return false; }

    From.submit();
    return true;
}
//娉ㄥ唽楠岃瘉
function isEmail(str) {
    var reg = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
    return reg.test(str);
}

function isEnglish(name) {
    if (name == '') return false;
    if (name.match(/[^\a-\z\A-\Z]/g)) return false;
    else return true;
}

function isTel(str) {
    var reg = /^[\d\-]+$/g;
    if (str.length <= 10 || str.length >= 12) {
        return false;
    }
    else {
        return reg.exec(str);
    }
}

function validate_recommen_mobile() {
    var mobile = $('#mobile').val();
    var recommenMobile = trimStr($('#tj_code').val()) || '没有推荐人请留空';
    if (recommenMobile != '' && recommenMobile != '没有推荐人请留空' && recommenMobile != '推荐人手机号/留空') {
        if (recommenMobile.match(/^1[0-9]{10}$/) == null && recommenMobile.toLowerCase() != 'dcm' && recommenMobile != '1335151' && recommenMobile.toLowerCase() != 'happynewyear' && recommenMobile.match(/^[a-zA-z]{2,3}1[0-9]{10}$/) == null && recommenMobile.match(/^[a-zA-z0-9]{6}$/) == null) {
            alert('请正确填写推荐人的手机号码，没有推荐人请留空');
            return false;
        } else if (mobile == recommenMobile) {
            alert('推荐人手机号不可以写自己的手机号哦，亲！');
            return false;
        } else {
            return true;
        }
    } else {
        return true;
    }
}


//鍘绘帀鍓嶅悗绌烘牸
function trimStr(value) {
    return value.replace(/(^\s*)|(\s*$)/g, "");
}

function chkRegister(From) {
    var email = document.getElementById('email');
    if (!isEmail(email.value))
    { alert('请输入正确的邮箱地址'); email.focus(); return false; }

    //瀵嗙爜
    var password = document.getElementById('password').value;
    if (password == "" || password == '此处设置密码' || password == '请输入用户密码') {
        alert('密码不能为空');
        return false;
    }

    if (password.length < 6 || password.length > 20) {
        alert('密码长度在6-20位之间');
        return false;
    }


    var tel = document.getElementById('mobile');
    if (!isTel(tel.value))
    { alert('请填写正确的联系号码'); tel.focus(); return false; }
    //鎺ㄨ崘浜虹殑鎵嬫満鍙风爜鏄惁鍚堟硶,鍚堟硶杩斿洖true鎻愪氦锛屼笉鍚堟硶杩斿洖false鍙栨秷鎻愪氦

    if (!validate_recommen_mobile())
    { return false; }


    From.submit();
    return true;
}
//鏀惰棌鏈珯
function AddFavorite(title, url) {
    try {
        window.external.addFavorite(url, title);
    } catch (e) {
        try {
            window.sidebar.addPanel(title, url, "");
        } catch (e) { //alert("鎶辨瓑锛屾偍鎵€浣跨敤鐨勬祻瑙堝櫒鏃犳硶瀹屾垚姝ゆ搷浣溿€俓n\n鍔犲叆鏀惰棌澶辫触锛岃浣跨敤Ctrl+D杩涜娣诲姞");
        }
    }
}
var browserEvent = function (obj, url, title) {
    var e = window.event || arguments.callee.caller.arguments[0];
    var B = {
        IE: /MSIE/.test(window.navigator.userAgent) && !window.opera
        , FF: /Firefox/.test(window.navigator.userAgent)
        , OP: !!window.opera
    };
    obj.onmousedown = null;
    if (B.IE) {
        obj.attachEvent("onmouseup", function () {
            try {
                window.external.AddFavorite(url, title);
                window.event.returnValue = false;
            } catch (exp) { }
        });
    } else {
        if (B.FF || obj.nodeName.toLowerCase() == "a") {
            obj.setAttribute("rel", "sidebar"), obj.title = title, obj.href = url;
        } else if (B.OP) {
            var a = document.createElement("a");
            a.rel = "sidebar", a.title = title, a.href = url;
            obj.parentNode.insertBefore(a, obj);
            a.appendChild(obj);
            a = null;
        }
    }
};  
